const merchantFacade = require('../../app/facade/merchant.facade.js'); 
const _  =  require('lodash');

module.exports = {
    merchantRegister: merchantRegister,
    getMerchantByLogin: getMerchantByLogin,
    getMerchantByIcnum: getMerchantByIcnum,
    merchantUpdate: merchantUpdate,
}

function merchantRegister(req, res, next){
    let merchant = req.body;
    merchantFacade.merchantRegister(merchant,(error, result)=>{
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
        }         
    });
}

function getMerchantByLogin(req, res, next){
    let merchant = req.body;
    merchantFacade.getMerchantByLogin(merchant,(error, result)=>{
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
        }         
    });
}

function getMerchantByIcnum(req, res, next){
    let params = req.params;
    let icnum = params.icnum;
    merchantFacade.getMerchantByIcnum(icnum,(error,result)=>{
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
        }        
    });

}


function merchantUpdate(req, res, next){
    let merchant = req.body;
    merchantFacade.merchantUpdate(merchant,(error,result)=>{
        if (error) {
            return next(new Error(error));
        } else {
            return res.json(result);
        }         
    });


}
